import 'package:city_pickers/meta/province.dart';
import 'package:flustars/flustars.dart';
import 'package:flutter/widgets.dart';
import 'package:yuan_hang_app/bean/user.dart';
import 'package:yuan_hang_app/utils/common_req_utils.dart';
import 'package:yuan_hang_app/utils/string_utils.dart';

import '../views/report/model/region_info.dart';

class WConstant {
  //密码加密密钥
  static const String encryptKey =
      'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC+qyoKFVePsvGQ9/RJJC9FT9FYF6kxuJ1l53P8GHMzTU9Jbbk2k///Hf5cpX8iP6laV24OT1KGLab/kUuUlT+1BSR4OsAUshASqYQbvzqSHn8DWJ9owovh3461Rksc1uS2xGABKzjcDi3nwHLkJ50bSLWpRxAKA+6TXo7mH0E4bQIDAQAB';

  static const String USERINFO = 'userInfo';
  static const String token = 'token';
  static const String userId = 'userId';
  static const String username = 'username';
  static const String password = 'password';
  static const String JPMessageReceive = "JPMessageReceive"; //极光推送收到消息
  static const String packageName = 'yuan_hang_app';
  static BuildContext? appContext;
  static GlobalKey<NavigatorState> navigatorKey = GlobalKey();
  static bool debug = true;

  static const int successCode = 200;

  static const int invalidateToken = 401;

  static const int otherError = -99;

  static String MODEL = "model";

  static int MODEL_INT = 2;

  static String API_HOST_OTTHER() {
    switch (MODEL_INT) {
      case 0:
        return "http://106.227.35.0:8085/";
      case 1:
        return "http://59.48.146.132:38085/";
      case 2:
        return "http://59.48.146.132:28085/";
      default:
        return "http://10.2.53.140:8085/";
    }
  }

  static List<Map> leaderSourceLst = [];
  static List<Map> intentRangeList = [];
  static List<Map> leadsStatusList = [];
  static List<Map> driveMethodList = [];
  static List<Map> driveTypeList = [];
  static List<Map> sexList = [];
  static List<Map> yesOrNoList = [];
  static List<Map> customerTypeList = [];
  static List<Map> cardTypeList = [];
  static List<Map> activityStatusList = [];
  static List<Map> buyCarWayList = [];
  static List<Map> payCarWayList = [];
  static List<Map> followUpWayList = [];
  static List<Map> followUpResultList = [];
  static List<Map> defeatResultList = [];
  static List<Map> invalidityReasonList = [];
  static List<Map> contactTypeList = [];
  static List<Map> driveStatusList = [];
  static List<Map> storeTypeList = [];
  static List<Map> bookStatusList = [];
  static List<Map> orderStatusList = [];
  static List<Map> appointTypeList = [];
  static List<Map> directStoreStatusList = [];
  static List<Map> activityLevelList = [];
  static List<Map> numOfInstallmentsList = [];
  static List<Map> financialInstitutionList = [];
  List<Map> salesmanList =
      CommonReqUtils.getLabelListByKey(CommonReqUtils.salesman); //销售顾问
  static List<Map> modelList = [];
  static List<Map> storeOrderStatusList = [];
  static List<Map> storeCarStatusList = [];
  static List<Map> storeMatchCarStatusList = [];
  static List<Map> storeLockStatusList = [];
  static List<Map> shopTypeList = [{"label": "直营店", "value":"10471001"},{"label": "经销商", "value":"10471002"}];


  static void initList() {
    leaderSourceLst = filterLeaderSourceList(); //线索来源1009
    intentRangeList = filterIntentRangeList(); //意向级别2430
    leadsStatusList =
        CommonReqUtils.getLabelListByKey(CommonReqUtils.leadsStatus); //线索状态1016
    driveMethodList =
        CommonReqUtils.getLabelListByKey(CommonReqUtils.driveMethod); //试驾方式2465
    driveTypeList =
        CommonReqUtils.getLabelListByKey(CommonReqUtils.driveType); //试驾类型2461
    sexList = CommonReqUtils.getLabelListByKey(CommonReqUtils.sex)
        .where((item) => item["label"] != "未知")
        .toList(); //性别1002
    yesOrNoList =
        CommonReqUtils.getLabelListByKey(CommonReqUtils.yesOrNo); //是否1004
    customerTypeList = CommonReqUtils.getLabelListByKey(
        CommonReqUtils.customerType); //客户类型2428
    cardTypeList =
        CommonReqUtils.getLabelListByKey(CommonReqUtils.cardType); //证件类型2431
    activityStatusList = CommonReqUtils.getLabelListByKey(
        CommonReqUtils.activityStatus); //市场活动状态1014
    buyCarWayList =
        CommonReqUtils.getLabelListByKey(CommonReqUtils.buyCarWay); //购车方式1024
    payCarWayList =
        CommonReqUtils.getLabelListByKey(CommonReqUtils.payCarWay); //早饭方式2711
    followUpWayList =
        CommonReqUtils.getLabelListByKey(CommonReqUtils.followUpWay); //跟进方式2442
    followUpResultList = CommonReqUtils.getLabelListByKey(
        CommonReqUtils.followUpResult); //跟进结果1910
    defeatResultList = CommonReqUtils.getLabelListByKey(
        CommonReqUtils.defeatResult); //战败原因1911
    invalidityReasonList = CommonReqUtils.getLabelListByKey(
        CommonReqUtils.invalidityReason); //无效原因1912
    contactTypeList =
        CommonReqUtils.getLabelListByKey(CommonReqUtils.contactType); //接触类型1013
    driveStatusList =
        CommonReqUtils.getLabelListByKey(CommonReqUtils.driveStatus); //试驾状态1018
    storeTypeList =
        CommonReqUtils.getLabelListByKey(CommonReqUtils.storeType); //门店类型1005
    bookStatusList =
        CommonReqUtils.getLabelListByKey(CommonReqUtils.bookStatus); //预约状态1021
    orderStatusList =
        CommonReqUtils.getLabelListByKey(CommonReqUtils.orderStatus); //订单状态1020
    appointTypeList = CommonReqUtils.getLabelListByKey(
        CommonReqUtils.appointType); //预约类型 1022
    directStoreStatusList = CommonReqUtils.getLabelListByKey(
        CommonReqUtils.directStoreStatus); //直营店类型1019
    activityLevelList = CommonReqUtils.getLabelListByKey(
        CommonReqUtils.activityLevel); //活动等级1017
    numOfInstallmentsList = CommonReqUtils.getLabelListByKey(
        CommonReqUtils.numOfInstallments); //分期数2710
    financialInstitutionList = CommonReqUtils.getLabelListByKey(
        CommonReqUtils.financialInstitution); //归属金融2468

    modelList = CommonReqUtils.getLabelListByKey(CommonReqUtils.carType); //意向车型

    storeOrderStatusList = CommonReqUtils.getLabelListByKey(
        CommonReqUtils.storeOrderStatus); //订单状态4003
    storeCarStatusList = CommonReqUtils.getLabelListByKey(
        CommonReqUtils.storeCarStatus); //车辆状态4009
    storeMatchCarStatusList = CommonReqUtils.getLabelListByKey(
        CommonReqUtils.storeMatchCarStatus); //配车状态4011
    storeLockStatusList = CommonReqUtils.getLabelListByKey(
        CommonReqUtils.storeLockStatus); //锁车状态4014
  }

  static List<Map> filterIntentRangeList() {
    List level = ["H", "A", "B", "C", "N"];
    List<Map> levelList =
        CommonReqUtils.getLabelListByKey(CommonReqUtils.intentRange);
    levelList =
        levelList.where((item) => level.contains(item["label"])).toList();
    var lastItem = levelList.removeLast();
    levelList.insert(0, lastItem);
    return levelList;
  }

  User userInfo = StringUtils.isEmpty(SpUtil.getString(USERINFO))
      ? User.fromJson2()
      : User.userFromJson(SpUtil.getString(USERINFO) ?? "{}");

  static List<Map> filterLeaderSourceList() {
    List sources = ["官网", "懂车帝", "易车网", "TSP", "汽车之家", "官方新媒体"];
    List<Map> sourcesList =
        CommonReqUtils.getLabelListByKey(CommonReqUtils.leaderSource);
    sourcesList =
        sourcesList.where((item) => !sources.contains(item["label"])).toList();
    return sourcesList;
  }

  static void cleanList() {
    leaderSourceLst = [];
    intentRangeList = [];
    defeatResultList = [];
    leadsStatusList = [];
    driveMethodList = [];
    driveTypeList = [];
    sexList = [];
    yesOrNoList = [];
    customerTypeList = [];
    cardTypeList = [];
    activityStatusList = [];
    buyCarWayList = [];
    payCarWayList = [];
    followUpWayList = [];
    followUpResultList = [];
    defeatResultList = [];
    invalidityReasonList = [];
    contactTypeList = [];
    driveStatusList = [];
    storeTypeList = [];
    bookStatusList = [];
    orderStatusList = [];
    appointTypeList = [];
    directStoreStatusList = [];
    activityLevelList = [];
    numOfInstallmentsList = [];
    financialInstitutionList = [];
    //salesmanList = [];
    modelList = [];
    storeOrderStatusList = [];
    storeMatchCarStatusList = [];
    storeCarStatusList = [];
    storeLockStatusList = [];
  }
}
